package com.boot.unity.api.modules.training.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.boot.unity.api.common.Result;
import com.boot.unity.api.modules.training.dao.StageTrainingTimeDao;
import com.boot.unity.api.modules.training.entity.StageTrainingTime;
import com.boot.unity.api.modules.training.service.StageTrainingTimeService;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author anonymous
 *
 * @create 2020-06-07 11:17:29
 */
@Service
@AllArgsConstructor
public class StageTrainingTimeServiceImpl implements StageTrainingTimeService {

    private final StageTrainingTimeDao stageTrainingTimeDao;

    @Override
    public Result save(StageTrainingTime stageTrainingTime) {
        List<String> recarray = stageTrainingTime.getRecarray();
        if (CollectionUtils.isNotEmpty(recarray)){
            String records = CollUtil.join(recarray,",");
            stageTrainingTime.setRecords(records);
        }
        int num = stageTrainingTimeDao.save(stageTrainingTime);
        if (num > 0){
            return Result.success();
        }
        return Result.fail();
    }
}
